package com.bootdo.blog.dao;

import com.bootdo.blog.domain.WineDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-12 07:50:17
 */
@Mapper
public interface WineMapper {

    @Select("select `wine_id`, `wine_name`, `wine_color`, `clarify`, `blister`, `aroma`, `taste`, `typicality`, `content_co2`, `sugar`, `volatiles`, `extract`, `alcoho`, `lemon`, `hcho`, `iron`, `steel`, `benzoic`, `sorbic`, `status` from tb_wine where wine_id = #{id}")
    WineDO get(Integer wineId);

    @Select("<script>" +
            "select * from tb_wine " +
            "<where>" +
            "<if test=\"wineId != null and wineId != ''\">" + "and wine_id = #{wineId} " + "</if>" +
            "<if test=\"wineName != null and wineName != ''\">" + "and wine_name = #{wineName} " + "</if>" +
            "<if test=\"wineColor != null and wineColor != ''\">" + "and wine_color = #{wineColor} " + "</if>" +
            "<if test=\"clarify != null and clarify != ''\">" + "and clarify = #{clarify} " + "</if>" +
            "<if test=\"blister != null and blister != ''\">" + "and blister = #{blister} " + "</if>" +
            "<if test=\"aroma != null and aroma != ''\">" + "and aroma = #{aroma} " + "</if>" +
            "<if test=\"taste != null and taste != ''\">" + "and taste = #{taste} " + "</if>" +
            "<if test=\"typicality != null and typicality != ''\">" + "and typicality = #{typicality} " + "</if>" +
            "<if test=\"contentCo2 != null and contentCo2 != ''\">" + "and content_co2 = #{contentCo2} " + "</if>" +
            "<if test=\"sugar != null and sugar != ''\">" + "and sugar = #{sugar} " + "</if>" +
            "<if test=\"volatiles != null and volatiles != ''\">" + "and volatiles = #{volatiles} " + "</if>" +
            "<if test=\"extract != null and extract != ''\">" + "and extract = #{extract} " + "</if>" +
            "<if test=\"alcoho != null and alcoho != ''\">" + "and alcoho = #{alcoho} " + "</if>" +
            "<if test=\"lemon != null and lemon != ''\">" + "and lemon = #{lemon} " + "</if>" +
            "<if test=\"hcho != null and hcho != ''\">" + "and hcho = #{hcho} " + "</if>" +
            "<if test=\"iron != null and iron != ''\">" + "and iron = #{iron} " + "</if>" +
            "<if test=\"steel != null and steel != ''\">" + "and steel = #{steel} " + "</if>" +
            "<if test=\"benzoic != null and benzoic != ''\">" + "and benzoic = #{benzoic} " + "</if>" +
            "<if test=\"sorbic != null and sorbic != ''\">" + "and sorbic = #{sorbic} " + "</if>" +
            "<if test=\"status != null and status != ''\">" + "and status = #{status} " + "</if>" +
            "</where>" +
            " <choose>" +
            "<when test=\"sort != null and sort.trim() != ''\">" +
            "order by ${sort} ${order}" +
            "</when>" +
            "<otherwise>" +
            "order by wine_id desc" +
            "</otherwise>" +
            "</choose>" +
            "<if test=\"offset != null and limit != null\">" +
            "limit #{offset}, #{limit}" +
            "</if>" +
            "</script>")
    List<WineDO> list(Map<String, Object> map);

    @Select("<script>" +
            "select * from tb_wine " +
            "<where>" +
            "<if test=\"wineId != null and wineId != ''\">" + "and wine_id = #{wineId} " + "</if>" +
            "<if test=\"wineName != null and wineName != ''\">" + "and wine_name = #{wineName} " + "</if>" +
            "<if test=\"wineColor != null and wineColor != ''\">" + "and wine_color = #{wineColor} " + "</if>" +
            "<if test=\"clarify != null and clarify != ''\">" + "and clarify = #{clarify} " + "</if>" +
            "<if test=\"blister != null and blister != ''\">" + "and blister = #{blister} " + "</if>" +
            "<if test=\"aroma != null and aroma != ''\">" + "and aroma = #{aroma} " + "</if>" +
            "<if test=\"taste != null and taste != ''\">" + "and taste = #{taste} " + "</if>" +
            "<if test=\"typicality != null and typicality != ''\">" + "and typicality = #{typicality} " + "</if>" +
            "<if test=\"contentCo2 != null and contentCo2 != ''\">" + "and content_co2 = #{contentCo2} " + "</if>" +
            "<if test=\"sugar != null and sugar != ''\">" + "and sugar = #{sugar} " + "</if>" +
            "<if test=\"volatiles != null and volatiles != ''\">" + "and volatiles = #{volatiles} " + "</if>" +
            "<if test=\"extract != null and extract != ''\">" + "and extract = #{extract} " + "</if>" +
            "<if test=\"alcoho != null and alcoho != ''\">" + "and alcoho = #{alcoho} " + "</if>" +
            "<if test=\"lemon != null and lemon != ''\">" + "and lemon = #{lemon} " + "</if>" +
            "<if test=\"hcho != null and hcho != ''\">" + "and hcho = #{hcho} " + "</if>" +
            "<if test=\"iron != null and iron != ''\">" + "and iron = #{iron} " + "</if>" +
            "<if test=\"steel != null and steel != ''\">" + "and steel = #{steel} " + "</if>" +
            "<if test=\"benzoic != null and benzoic != ''\">" + "and benzoic = #{benzoic} " + "</if>" +
            "<if test=\"sorbic != null and sorbic != ''\">" + "and sorbic = #{sorbic} " + "</if>" +
            "<if test=\"status != null and status != ''\">" + "and status = #{status} " + "</if>" +
            "</where>" +
            "</script>")
    List<WineDO> list2(WineDO wineDO);

    @Select("<script>" +
            "select count(*) from tb_wine " +
            "<where>" +
            "<if test=\"wineId != null and wineId != ''\">" + "and wine_id = #{wineId} " + "</if>" +
            "<if test=\"wineName != null and wineName != ''\">" + "and wine_name = #{wineName} " + "</if>" +
            "<if test=\"wineColor != null and wineColor != ''\">" + "and wine_color = #{wineColor} " + "</if>" +
            "<if test=\"clarify != null and clarify != ''\">" + "and clarify = #{clarify} " + "</if>" +
            "<if test=\"blister != null and blister != ''\">" + "and blister = #{blister} " + "</if>" +
            "<if test=\"aroma != null and aroma != ''\">" + "and aroma = #{aroma} " + "</if>" +
            "<if test=\"taste != null and taste != ''\">" + "and taste = #{taste} " + "</if>" +
            "<if test=\"typicality != null and typicality != ''\">" + "and typicality = #{typicality} " + "</if>" +
            "<if test=\"contentCo2 != null and contentCo2 != ''\">" + "and content_co2 = #{contentCo2} " + "</if>" +
            "<if test=\"sugar != null and sugar != ''\">" + "and sugar = #{sugar} " + "</if>" +
            "<if test=\"volatiles != null and volatiles != ''\">" + "and volatiles = #{volatiles} " + "</if>" +
            "<if test=\"extract != null and extract != ''\">" + "and extract = #{extract} " + "</if>" +
            "<if test=\"alcoho != null and alcoho != ''\">" + "and alcoho = #{alcoho} " + "</if>" +
            "<if test=\"lemon != null and lemon != ''\">" + "and lemon = #{lemon} " + "</if>" +
            "<if test=\"hcho != null and hcho != ''\">" + "and hcho = #{hcho} " + "</if>" +
            "<if test=\"iron != null and iron != ''\">" + "and iron = #{iron} " + "</if>" +
            "<if test=\"steel != null and steel != ''\">" + "and steel = #{steel} " + "</if>" +
            "<if test=\"benzoic != null and benzoic != ''\">" + "and benzoic = #{benzoic} " + "</if>" +
            "<if test=\"sorbic != null and sorbic != ''\">" + "and sorbic = #{sorbic} " + "</if>" +
            "<if test=\"status != null and status != ''\">" + "and status = #{status} " + "</if>" +
            "</where>" +
            "</script>")
    int count(Map<String, Object> map);

    @Select("select count(*) from tb_wine where status = #{status}")
    int count2(int status);

    @Insert("insert into tb_wine (`wine_name`, `wine_color`, `clarify`, `blister`, `aroma`, `taste`, `typicality`, `content_co2`, `sugar`, `volatiles`, `extract`, `alcoho`, `lemon`, `hcho`, `iron`, `steel`, `benzoic`, `sorbic`, `status`)"
            + "values (#{wineName}, #{wineColor}, #{clarify}, #{blister}, #{aroma}, #{taste}, #{typicality}, #{contentCo2}, #{sugar}, #{volatiles}, #{extract}, #{alcoho}, #{lemon}, #{hcho}, #{iron}, #{steel}, #{benzoic}, #{sorbic}, #{status})")
    int save(WineDO wine);

    @Update("<script>" +
            "update tb_wine " +
            "<set>" +
            "<if test=\"wineId != null\">`wine_id` = #{wineId}, </if>" +
            "<if test=\"wineName != null\">`wine_name` = #{wineName}, </if>" +
            "<if test=\"wineColor != null\">`wine_color` = #{wineColor}, </if>" +
            "<if test=\"clarify != null\">`clarify` = #{clarify}, </if>" +
            "<if test=\"blister != null\">`blister` = #{blister}, </if>" +
            "<if test=\"aroma != null\">`aroma` = #{aroma}, </if>" +
            "<if test=\"taste != null\">`taste` = #{taste}, </if>" +
            "<if test=\"typicality != null\">`typicality` = #{typicality}, </if>" +
            "<if test=\"contentCo2 != null\">`content_co2` = #{contentCo2}, </if>" +
            "<if test=\"sugar != null\">`sugar` = #{sugar}, </if>" +
            "<if test=\"volatiles != null\">`volatiles` = #{volatiles}, </if>" +
            "<if test=\"extract != null\">`extract` = #{extract}, </if>" +
            "<if test=\"alcoho != null\">`alcoho` = #{alcoho}, </if>" +
            "<if test=\"lemon != null\">`lemon` = #{lemon}, </if>" +
            "<if test=\"hcho != null\">`hcho` = #{hcho}, </if>" +
            "<if test=\"iron != null\">`iron` = #{iron}, </if>" +
            "<if test=\"steel != null\">`steel` = #{steel}, </if>" +
            "<if test=\"benzoic != null\">`benzoic` = #{benzoic}, </if>" +
            "<if test=\"sorbic != null\">`sorbic` = #{sorbic}, </if>" +
            "<if test=\"status != null\">`status` = #{status}, </if>" +
            "</set>" +
            "where wine_id = #{wineId}" +
            "</script>")
    int update(WineDO wine);

    @Delete("delete from tb_wine where wine_id =#{wineId}")
    int remove(Integer wine_id);

    @Delete("<script>" +
            "delete from tb_wine where wine_id in " +
            "<foreach item=\"wineId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" +
            "#{wineId}" +
            "</foreach>" +
            "</script>")
    int batchRemove(Integer[] wineIds);
}
